<?php
/* SVN FILE: $Id: statistics_players_controller.php 250 2010-06-17 10:55:41Z gregory.rome $ */
/**
 * StatisticsPlayers Controller.
 *
 * cBBweb : Digital Blood Bowl league interface (http://code.google.com/p/cbbweb/)
 * Copyright 2009-2010, Grégory Romé.
 *
 * Licensed under The MIT License
 * Redistributions of files must retain the above copyright notice.
 *
 * @filesource
 * @copyright     Copyright 2009-2010, Grégory Romé.
 * @link          http://code.google.com/p/cbbweb/ cBBweb Project
 * @package       cbbweb
 * @subpackage    cbbweb.controllers
 * @version       $Revision: 250 $
 * @modifiedby    $LastChangedBy: gregory.rome $
 * @lastmodified  $Date: 2010-06-17 10:55:41 +0000 (Thu, 17 Jun 2010) $
 * @license       http://www.opensource.org/licenses/mit-license.php The MIT License
 */

/**
 * StatisticsPlayers Controller.
 *
 * @package       cbbweb
 * @subpackage    cbbweb.controllers
 */
class StatisticsPlayersController extends AppController {

	var $name = 'StatisticsPlayers';

	function index($filter=null) {

		$this-> paginate['StatisticsPlayer'] = array(
  		'order' => array(
				'StatisticsPlayer.Inflicted_iTouchdowns' => 'desc',
				'Player.iExperience' => 'desc',
				'Player.iValue' => 'desc'),
			'limit' => 10,
			'fields' => array(
				'ID',	'idPlayer_Listing',	'iMatchPlayed',	'iMVP',	'Inflicted_iPasses"',
				'Inflicted_iCatches',	'Inflicted_iInterceptions',	'Inflicted_iTouchdowns"',
				'Inflicted_iCasualties', 'Inflicted_iTackles',	'Inflicted_iKO"',
				'Inflicted_iStuns',	'Inflicted_iInjuries', 'Inflicted_iDead"',
				'Inflicted_iMetersRunning',	'Inflicted_iMetersPassing"',
				'Sustained_iInterceptions',	'Sustained_iCasualties"',
				'Sustained_iTackles',	'Sustained_iKO', 'Sustained_iStuns"',
				'Sustained_iInjuries', 'Sustained_iDead"',
				'(CAST(Inflicted_iPasses AS REAL) / iMatchPlayed) AS "Inflicted_fAvgPasses"',
				'(Inflicted_iCatches / iMatchPlayed) AS "Inflicted_fAvgCatches"',
				'(Inflicted_iInterceptions / iMatchPlayed) AS "Inflicted_fAvgInterceptions"',
				'(CAST(Inflicted_iTouchdowns AS REAL) / iMatchPlayed) AS "Inflicted_fAvgTouchdowns"',
				'(Inflicted_iCasualties / iMatchPlayed) AS "Inflicted_fAvgCasualties"',
				'(Inflicted_iTackles / iMatchPlayed) AS "Inflicted_fAvgTackles"',
				'(Inflicted_iKO / iMatchPlayed) AS "Inflicted_fAvgKO"',
				'(Inflicted_iStuns / iMatchPlayed) AS "Inflicted_fAvgStuns"',
				'(Inflicted_iInjuries / iMatchPlayed) AS "Inflicted_fAvgInjuries"',
				'(Inflicted_iDead / iMatchPlayed) AS "Inflicted_fAvgDead"',
				'(Inflicted_iMetersRunning / iMatchPlayed) AS "Inflicted_fAvgMetersRunning"',
				'(Inflicted_iMetersPassing / iMatchPlayed) AS "Inflicted_fAvgMetersPassing"',
				'(Sustained_iInterceptions / iMatchPlayed) AS "Sustained_fAvgInterceptions"',
				'(Sustained_iCasualties / iMatchPlayed) AS "Sustained_fAvgCasualties"',
				'(Sustained_iTackles / iMatchPlayed) AS "Sustained_fAvgTackles"',
				'(Sustained_iKO / iMatchPlayed) AS "Sustained_fAvgKO"',
				'(Sustained_iStuns / iMatchPlayed) AS "Sustained_fAvgStuns"',
				'(Sustained_iInjuries / iMatchPlayed) AS "Sustained_fAvgInjuries"'
			),
  		'contain' => array(
				'Player' => array(
					'fields' => array(
						'Player.ID',
						'Player.strName',
						'Player.idTeam_Listing',
						'Player.iValue',
						'Player.iExperience'),
					'Team' => array(
						'fields' => array('Team.ID, Team.strName')
					)
				)
			)
  	);

  	$this->debug($this->data);

		$this->set('statisticsPlayers', $this->paginate('StatisticsPlayer'));
	}

	function view($id = null) {
		if (!$id) {
			$this->flash(__('Invalid Player Statistics', true), array('action' => 'index'));
		}
		$this->set('statisticsPlayer', $this->StatisticsPlayer->read(null, $id));
	}

	function delete($id = null) {
		if (!$id) {
			$this->flash(__('Invalid Player Statistics', true), array('action' => 'index'));
		}
		if ($this->StatisticsPlayer->del($id)) {
			$this->flash(__('Player Statistics deleted', true), array('action' => 'index'));
		}
		$this->flash(__('The Player Statistics could not be deleted. Please, try again.', true), array('action' => 'index'));
	}

}
?>